/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.payment.handler.pay;

import com.egzosn.pay.common.http.UriVariables;
import com.egzosn.pay.spring.boot.core.PayServiceManager;
import com.medusa.gruul.common.core.auth.model.enums.Platform;
import com.medusa.gruul.common.core.exception.ServiceException;
import com.medusa.gruul.payment.api.model.pay.PayParam;
import com.medusa.gruul.payment.common.annotation.PlatformHandler;
import com.medusa.gruul.payment.common.model.PayRequestOrder;
import com.medusa.gruul.payment.service.MultiPayOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * app支付
 *
 * @author 张治保
 * date 2022/1/11
 */
@Slf4j
@Component
@PlatformHandler({Platform.APP})
public class AppPayHandler extends AbstractPlatformPayHandler {

    protected final PayServiceManager payServiceManager;

    public AppPayHandler(MultiPayOrderService multiPayOrderService, PayServiceManager payServiceManager) {
        super(multiPayOrderService);
        this.payServiceManager = payServiceManager;
    }

    @Override
    protected Object payData(PayParam payParam, PayRequestOrder payOrder) {
        log.info("===App支付:正在生成支付订单详情");

        Map<String, Object> orderInfo = payServiceManager.app(payOrder);
        switch (payParam.getPayType()){
            case ALIPAY:
                return UriVariables.getMapToParameters(orderInfo);
            case WECHAT:
                return orderInfo;
            default:
                break;
        }
        throw new ServiceException("暂不支持的支付方式.");
    }
}
